package com.ruirenyun.entity.base.resp;

import com.github.pagehelper.Page;
import lombok.Getter;
import lombok.Setter;

import java.util.Collection;
import java.util.List;

/**
 * @author Deng Ye
 * @version 1.0
 * @date 2020/11/23
 * @description
 * @modifiedBy 通用分页响应对象
 */
@Getter
@Setter
public class PageRespVo<T> extends AbstractResponseVo {
    private static final long serialVersionUID = -1979021015119806619L;

    private List<T> list;
    private int pageSize;
    private int pageNum;
    private Long total;
    public PageRespVo(List<T> list) {
        this.list = list;
        if (list instanceof Page) {
            Page page = (Page) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.total = page.getTotal();
        } else if (list instanceof Collection) {
            this.pageNum = 1;
            this.pageSize = list.size();
            this.total = (long)list.size();
        }
    }
}
